package cn.yunhe.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	private static final String FMT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
	private static final String FMT_DATE = "yyyy-MM-dd";
	private static final String FMT_TIME = "HH:mm:ss";

	public static String date2StringDateTime(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FMT_DATE_TIME);
		return sdf.format(date);
	}

	public static String date2StringDate(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FMT_DATE);
		return sdf.format(date);
	}

	public static String date2StringTime(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FMT_TIME);
		return sdf.format(date);
	}
	public static Date stringDate2date(String dateStr) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(FMT_DATE);
		 return sdf.parse(dateStr);
	}
	public static Date stringDateTime2date(String dateStr) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(FMT_DATE_TIME);  
		 return sdf.parse(dateStr);
	}
	public static Date stringTime2date(String dateStr) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(FMT_TIME);  
		 return sdf.parse(dateStr);
	}
	public static java.sql.Date getSqlDate(){
		Date date = new Date();
		java.sql.Date dateTime = new java.sql.Date(date.getTime());
		return dateTime;
	}
}
